import os
import switch_control.telnetAPI as telnetAPI
import time
import threading
import gpu_port_ip_map as Port_ip_map

gpu_spine_port_map = {}
spine_port_gpu_map = {}
spine_port_vpn_map = {}
vrf_list = ["vrf1", "vrf2", "vrf3", "vrf4"]
GPU_NUM = 64
SERVER_GPU_NUM = 8
comm_list = []

PORT_PER_VPN = 4

for vpn_id in range(4):
    for i in range(8):
        spine_port_vpn_map[i*4+vpn_id] = vpn_id

def generate_spine_ip(host_ip = '10.174.216.48'):
    username = 'admin1234'
    password = 'Oxc_2012'
    changepwd = 'N'

    commit = 'commit'
    quit = 'q'
    sy = "system-view"
    admin = "admin"
    port_mode = "port-mode port"
    confirm = "Y"

    comm_list.append(sy)

    for spine_id in range(32):
        comm_list.append("int %s" %Port_ip_map.find_spine_port(spine_id*2))
        comm_list.append("undo portswitch")
        comm_list.append("ip address %s 255.255.255.0" %Port_ip_map.find_spine_ip(spine_id*2))
        comm_list.append("commit")

    for cmd in comm_list:
        print(cmd)

    # telnet_client = telnetAPI.TelnetClient()
    # if telnet_client.login_host(host_ip, username, password, changepwd):
    #     for cmd in comm_list:
    #         telnet_client.execute_some_command(cmd, interval=0.1)
    # else:
    #     print("fail")
    #     time.sleep(3)


generate_spine_ip('10.174.216.48')